package IOTest;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;

public class FileBinaryCopy {
    public static void main(String[] args) {
        Long start = System.currentTimeMillis();
        Long end = 0L;
        File f_src = new File("origin.png");
        File f_dest = new File("copy.png");
        if (f_src.exists()) {
            FileInputStream fis = null;
            FileOutputStream fos = null;
            try {
                fis = new FileInputStream(f_src);
                fos = new FileOutputStream(f_dest);

                byte[] b = new byte[1024];
                int len;
                while ((len = fis.read(b)) != -1) {
                    fos.write(b, 0, len);
                }
            } catch (Exception e) {
                e.printStackTrace();
            } finally {
                try {
                    fis.close();
                    fos.close();
                    end = System.currentTimeMillis();
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        }
        System.out.println("Time used: " + (end - start) + "ms");
    }
}
